package com.itgaoshu.hospitalproject.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itgaoshu.hospitalproject.bean.Litem;
import com.itgaoshu.hospitalproject.bean.Lrecord;
import com.itgaoshu.hospitalproject.service.LDrugService;
import com.itgaoshu.hospitalproject.service.LitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("liao")
//项目记账管理
public class LitemController {
    @Autowired
    private LitemService litemService;
    @Autowired
    private LDrugService lDrugService;

    //跳转项目记账页面
    @RequestMapping("item")
    public String item(){
        return "liao/item";
    }

    //查询所有的检查项目
    @RequestMapping("selItems")
    @ResponseBody
    public Object selItems(Integer page,Integer limit,Litem litem){
        PageHelper.startPage(page,limit);
        List<Litem> litems = litemService.selItems(litem);
        PageInfo pageInfo = new PageInfo(litems);
        Map<String,Object> tableDate = new HashMap<>();
        tableDate.put("code",0);
        tableDate.put("msg","");
        tableDate.put("count",pageInfo.getTotal());
        tableDate.put("data",pageInfo.getList());
        return tableDate;
    }

    //查询该患者的项目清单
    @ResponseBody
    @RequestMapping("selItem")
    public Object selItem(Integer page, Integer limit, Lrecord lrecord){
        lrecord.setState(1);//没动过手术的状态
        PageHelper.startPage(page,limit);
        List<Lrecord> lrecords = lDrugService.selDrugs(lrecord);
        PageInfo pageInfo = new PageInfo(lrecords);
        Map<String,Object> tableDate = new HashMap<>();
        tableDate.put("code",0);
        tableDate.put("msg","");
        tableDate.put("count",pageInfo.getTotal());
        tableDate.put("data",pageInfo.getList());
        return tableDate;
    }


    //给该患者添加收费项目
    @RequestMapping("addItem")
    @ResponseBody
    public Object addItem(Lrecord lrecord){
        lrecord.setState(1);
        lrecord.setDurgnum(1);
        lrecord.setRepicetotal(lrecord.getDurgnum()*lrecord.getRepiceprice());
        int i = litemService.addItem(lrecord);
        if(i==1){//添加成功
            return "添加成功";
        }else{
            return "添加失败";
        }
    }

    //删除该患者的项目根据id来删除
    @RequestMapping("/delItem")
    @ResponseBody
    public Object delItem(Integer hospitalpriceid){
        //这边只能接收id，因为htime已经转换成字符串了，lrecored不能再继续进行接收了
        Lrecord lrecord = new Lrecord();
        lrecord.setHospitalpriceid(hospitalpriceid);
        int i = lDrugService.delDrug(lrecord);
        if(i==1){
            return "移除成功";
        }else{
            return "移除失败";
        }
    }








}
